package com.woniuxy.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.entity.MBlog;
import com.woniuxy.entity.MBlogExample;
import com.woniuxy.mapper.MBlogMapper;
import com.woniuxy.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    MBlogMapper blogMapper;

    @Override
    public int postBlog(String loginId, MBlog blog) {
        blog.setUserId(Long.valueOf(loginId));
        blog.setStatus((byte) 1);
        blog.setCreated(new Date());
        return blogMapper.insertSelective(blog);
    }

    @Override
    public int delBlog(Integer id) {
        return blogMapper.deleteByPrimaryKey(id.longValue());
    }

    @Override
    public List search(Integer loginId) {
        MBlogExample mBlogExample = new MBlogExample();
        mBlogExample.or().andUserIdEqualTo(Long.valueOf(loginId));
        return blogMapper.selectByExample(mBlogExample);
    }
}
